//.serach form input
//.serach form   .serachButton
//.serach form .serachRes ul li a
//.serach form .serachRes ul .close
(function() {
	var serachBox = $('.serach form input');
	//先获取关键字
	$.get('/serach/keyWord', function(resData) {

		//		console.log(resData);
		serachBox.val(resData);
	});

	var serachRes = $('.serach form .serachRes');
	var serachClose = $('.serach form .serachRes ul');
	//	console.log(serachRes.find('ul .close'));
	serachClose.on('click', '.close', function() {
		//		console.log('点击关');
		serachRes.hide();

	});

	serachBox.keyup(function() {
		//不管有没有结果返回，先隐藏
		serachRes.hide();
		//		console.log($(this).val());
		//		console.log($(this).val().length);
		var keyWord = $(this).val();
		if($(this).val().length　 != 0) {

			$.get('/serach/returnResult', { "keyWord": keyWord }, function(resData) {

				if(resData.code != 2) {
					//有结果
					var resArry = resData.message;
					var html = '';
					$.each(resArry, function(index, value, array) {

						html += '<li><a href="">' + value + '</a></li>';

					});

					var ResUl = $('.serach form .serachRes ul');
					html += '<div class="close"><a >关闭</a></div>';
					ResUl.html(html);
					serachRes.show();

				} else {
					//没结果
				}

			});
		}

	});

})()